import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomeController extends GetxController with WidgetsBindingObserver {
  var tabIndex = 0.obs;

  void changeTabIndex(int index) {
    tabIndex.value = index;
  }


  @override
  void onInit() {
    super.onInit();
    WidgetsBinding.instance.addObserver(this); // 注册观察者
  }

  @override
  void onClose() {
    WidgetsBinding.instance.removeObserver(this); // 移除观察者
    super.onClose();
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    if (state == AppLifecycleState.resumed) {
      onResume();
    } else if (state == AppLifecycleState.paused) {
      onPause();
    }
  }

  void onResume() {
    // 处理恢复时的逻辑
    print("App Resumed");
  }

  void onPause() {
    // 处理挂起时的逻辑
    print("App Paused");
  }
}
